Skip to content

gh-160598: Decode labels read from a Babyl mailbox file - #160613

Open
devdavidejesus wants to merge 1 commit into
python:mainfrom
devdavidejesus:fix-babyl-labels-bytes
Open

devdavidejesus wants to merge 1 commit into
python:mainfrom
devdavidejesus:fix-babyl-labels-bytes

Conversation

@devdavidejesus

@devdavidejesus devdavidejesus commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Babyl._generate_toc() kept the labels read from the file as bytes, but they are written with label.encode() and everything else expects strings. As a result, labels read back were bytes, 'unseen' in msg.get_labels() was false (so unseen messages became read when converted to Maildir or mbox), Babyl.get_labels() included the special labels, and rewriting the mailbox failed with AttributeError. Decode them the same way they are encoded. Both directions use errors='surrogateescape', so a mailbox with labels that are not valid UTF-8 can still be opened (as it can today) and its labels are written back unchanged.

The two new tests reopen the mailbox; they fail without the change and pass with it, and test_mailbox passes. Tested on macOS.

See #160598.

Babyl._generate_toc() kept the labels read from the file as bytes, but
they are written with str.encode() and the rest of the code expects
strings.  Use errors='surrogateescape' in both directions so that labels
that are not valid UTF-8 still round-trip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant